package epam.bank.domain;

import org.hibernate.annotations.Type;
import org.joda.time.DateTime;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*;


@Entity
@Table(name = "PAYMENT")
@NamedQueries({
        @NamedQuery(name = "Payment.getByPayment", query = "SELECT p FROM Payment p WHERE p.invoice.id = ?1"),
        @NamedQuery(name = "Payment.deleteAllPayment", query = "DELETE FROM Payment p WHERE p.invoice.id = ?1") })
public class Payment extends DomainObject {

    @Column(name = "DATE_PAYMENT")
    @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
    private DateTime date;

    @Column(name = "CODE_PAYMENT")
    private String code;

    @Column(name = "SUM_PAYMENT")
    private int sum;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "INVOICE_ID")
    private Invoice invoice;

    public Payment() {
        super();
    }

    public DateTime getDate() {
        return date;
    }

    public void setDate(DateTime date) {
        this.date = date;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public int getSum() {
        return sum;
    }

    public void setSum(int sum) {
        this.sum = sum;
    }

    public Invoice getInvoice() {
        return invoice;
    }

    public void setInvoice(Invoice invoice) {
        this.invoice = invoice;
    }
}